import requests


def getHTMLText(url):
    try:
        r=requests.get(url,timeout=30)
        r.raise_for_status()#当状态不是200.引发http error异常
        r.encodingz=r.apparent_encoding
        return r.text
    except:
        return '产生异常'

if __name__=="__main__":
    url='http://www.baidu.com'
    print(getHTMLText(url))

